package com.zking.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zking.entity.Order;
import com.zking.mapper.IOrderMapper;
import com.zking.service.IOrderService;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController @RequiredArgsConstructor
public class MyController1 {
    // private final IOrderMapper orderMapper;
    // private final OrderServiceImpl orderService;
    private final IOrderService orderService;
    
    @GetMapping("/t1")
    public Page<Order> test1(@RequestParam(name = "page", defaultValue = "1") int pageNum) {
        // return orderService.list();
        // 分页
        return orderService.page(Page.of(pageNum, 2));
    }
    
    @GetMapping("/t2")
    public Page<Order> test2(
            String name,    // 名字精确匹配
            String address, // 地址模糊搜索
            Double min, // 最低价格
            Double max, // 最高价格
            Timestamp date1, // 测试Timestamp传递毫秒数：yyyy-mm-dd hh:mm:ss
            Date date2,      // 测试Date/Datetime传递日期：2023/12/01
            @RequestParam(name = "page", defaultValue = "1") int pageNum
    ) {
        // return orderService.page(Page.of(pageNum, 2));
        
        // 参数过长：1. 封装为一个Dto对象，2. 封装为一个Map对象
        // return orderService.search(name, address, min, max, date1, date2, pageNum, 2);
        
        Map<String, Object> map = new HashMap<>();
        map.put("name", name);
        map.put("address", address);
        map.put("min", min);
        map.put("max", max);
        map.put("date1", date1);
        map.put("date2", date2);
        return orderService.search(pageNum, 2, map);
    }
}
